package com.ruoyi.neo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.neo.domain.PartCategory;
import com.ruoyi.neo.service.IPartCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件分类Controller
 * 
 * @author ruoyi
 * @date 2025-03-09
 */
@RestController
@RequestMapping("/neo/partCategory")
public class PartCategoryController extends BaseController
{
    @Autowired
    private IPartCategoryService partCategoryService;

    /**
     * 查询零件分类列表
     */
//    @PreAuthorize("@ss.hasPermi('neo:partCategory:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(PartCategory partCategory)
//    {
//        startPage();
//        List<PartCategory> list = partCategoryService.selectPartCategoryInNeo4j(partCategory);
//        return getDataTable(list);
//    }
//    graph渲染
    @GetMapping("/list")
    public AjaxResult getPartCategoryGraph() {
     List<PartCategory> categories = partCategoryService.selectPartCategoryInNeo4j(new PartCategory());
        return success(categories);
    }
    /**
     * 导出零件分类列表
     */
    @PreAuthorize("@ss.hasPermi('neo:partCategory:export')")
    @Log(title = "零件分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartCategory partCategory)
    {
        List<PartCategory> list = partCategoryService.selectPartCategoryList(partCategory);
        ExcelUtil<PartCategory> util = new ExcelUtil<PartCategory>(PartCategory.class);
        util.exportExcel(response, list, "零件分类数据");
    }

    /**
     * 获取零件分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('neo:partCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(partCategoryService.selectPartCategoryByCategoryId(categoryId));
    }

    /**
     * 新增零件分类
     */
    @PreAuthorize("@ss.hasPermi('neo:partCategory:add')")
    @Log(title = "零件分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartCategory partCategory)
    {
        return toAjax(partCategoryService.insertPartCategory(partCategory));
    }

    /**
     * 修改零件分类
     */
    @PreAuthorize("@ss.hasPermi('neo:partCategory:edit')")
    @Log(title = "零件分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartCategory partCategory)
    {
        return toAjax(partCategoryService.updatePartCategoryInNeo4j(partCategory));
    }

    /**
     * 删除零件分类
     */
    @PreAuthorize("@ss.hasPermi('neo:partCategory:remove')")
    @Log(title = "零件分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryNames}")
    public AjaxResult remove(@PathVariable String[] categoryNames)
    {
        for(String s: categoryNames){
            System.out.println(s);
        }
        return toAjax(partCategoryService.deletPartCategoryByCategoryNamesInNeo4j(categoryNames));
    }
    //neo4j

    @GetMapping(value = "getById/{categoryId}")
    public PartCategory getById(@PathVariable("categoryId") Long categoryId)
    {
        return partCategoryService.selectPartCategoryByCategoryId(categoryId);
    }


}
